package worldLogic;

/**
 * Created by IntelliJ IDEA.
 * User: Mark the intern
 * Date: 14-Jul-2007
 * Time: 11:26:52 PM
 */
public class Counter {

    Integer maxValue;
    Integer value;

    public void setValue(Integer value) {
        this.value = value;
    }

    public Counter(int maxValue, int value) {
        this.maxValue = maxValue;
        while (value < 0) {
            value = value + maxValue;
        }
        this.value = value % maxValue;
    }

    public Counter add(int addAmount) {
        value = (value + addAmount) % maxValue;
        return this;
    }

    public Counter subtract(int subAmount) {
        while (value < 0) {
            value = value + maxValue;
        }
        return this;
    }

    public Integer getMaxValue() {
        return maxValue;
    }

    public Integer getValue() {
        return value;
    }

    public String toString() {
        return value.toString();
    }


}
